package com.five.welcome.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.welcome.entity.Studentinfo;
import com.five.welcome.dao.StudentinfoMapper;
import com.five.welcome.service.StudentinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ywt
 * @since 2024-07-11
 */
@Service
public class StudentinfoServiceImpl extends ServiceImpl<StudentinfoMapper, Studentinfo> implements StudentinfoService {

    @Autowired
    private StudentinfoMapper studentinfoMapper;

    @Override
    public int addStudent(Studentinfo studentinfo) {
        return studentinfoMapper.insert(studentinfo);
    }

    @Override
    public Studentinfo getInfoBySNumber(String sNumber) {
        QueryWrapper<Studentinfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("s_number", sNumber);
        return studentinfoMapper.selectOne(queryWrapper);
    }

    @Override
    public Page<Studentinfo> myPage(Integer pageNumber, Integer pageSize,
                                    String sNumber, String major, String classes) {
        Page<Studentinfo> page = Page.of(pageNumber, pageSize);
        QueryWrapper<Studentinfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(sNumber != null, "s_number", sNumber)
                .eq(major != null, "major", major)
                .eq(classes != null, "class", classes);
        page(page, queryWrapper);
        return page;
    }
}
